const path = require('path')

const resolve = dir => {
  return path.join(__dirname, dir)
}

module.exports = {
  /*
   * Project deployment base
   * By default we assume your app will be deployed at the root of a domain,
   * e.g. https://www.my-app.com/
   * If your app is deployed at a sub-path, you will need to specify that
   * sub-path here. For example, if your app is deployed at
   * https://www.foobar.com/my-app/
   * then change this to '/my-app/'
   *
   * 设置静态文件加载地址，在生产环境中如果入口文件（index）与静态文件不在同一个服务器，通过设置这个地址来加载远程静态文件
   * e.g, publicPath: 'http://static.vagrant.com/vue-admin-fontend-rbac/dist/', 注意需要设置静态文件服务器的 .woff2 、 .woff 、.ttf 等文件可以跨域访问
   *
   * 静态文件跨域跨域设置例子
   *
   * location ~ (\.ttf|\.woff2|\.woff)$ {
   *    add_header 'Access-Control-Allow-Origin' *;
   *    add_header 'Access-Control-Allow-Methods'  GET,POST,PUT,DELETE,OPTIONS;
   *    add_header 'Access-Control-Allow-Headers' 'Platform, Authorization, Accept, DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
   * }
   */
    publicPath         : process.env.NODE_ENV === 'production' ? process.env.VUE_APP_PAGE_URI_PRE : '/',
  /*
   * tweak internal webpack configuration.
   * see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
   * 如果你不需要使用eslint，把lintOnSave设为false即可
   */
  lintOnSave: false,
  chainWebpack: config => {
    config.resolve.alias
      .set('@', resolve('src')) // key,value自行定义，比如.set('@@', resolve('src/components'))
      .set('_c', resolve('src/components'))
  },

    // 设为false打包时不生成.map文件
    productionSourceMap: process.env.NODE_ENV !== 'production',
    /*
     * 这里写你调用接口的基础路径，来解决跨域，如果设置了代理，那你本地开发环境的axios的baseUrl要写为 '' ，即空字符串
     * devServer: {
     *   proxy: 'localhost:3000'
     * }
     */
    devServer          : {
        proxy: process.env.VUE_APP_DEV_BASE_API || 'http://localhost:8080'
    },

    /**
     * 打包文件输出保存的文件目录
     * e.g, outputDir: '../../../public/admin'
     * e.g, outputDir: './dist'
     */
    outputDir: '../../public/admin',

    // webpack配置
    configureWebpack:{
        optimization: {
            splitChunks: {// 分割大的打包块
                minSize: 126000,
                maxSize: 230000
            }
        }
    }
}
